<!DOCTYPE html>
<html lang="en">
<head>
  <title>浩然金融中心管理平台</title>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"
        name="viewport">
  <#include "/common/csslib.html">
  <script type="text/javascript">
      var useMethodTextArea;
      var methodContentAnalysisArea;
  </script>
</head>
<body>
<div class="main-wrapper">
  <!-- start: MAIN CONTAINER -->
  <div class="main-container inner">
    <!-- start: PAGE -->
    <div class="main-content">
      <div class="container">
        <div class="row h-main-search">
          <form action="javascript:;" method="post">
            <div class="pull-right h-btn-group">
              <button class="btn btn-info" id="return-btn" onclick="returnIndex()"><i class="fa fa-mail-reply">&nbsp;&nbsp;</i>返回
              </button>
              <@permission btnType="save" btnId="saveBtn" btnValue="保存" op="api:facadeMethod:save"
              btnMethod="ApiFacadeMethodMgr.submitForm()"/>
            </div>
          </form>
        </div>

        <div class="form-horizontal  h-form-warp">
          <div class="h-msg-title h-table-header">
            <strong>api接口方法信息</strong>
          </div>
          <form action="/apiFacadeMethod/saveApiFacadeMethod" class="form-horizontal" id="apiFacadeMethodForm"
                method="post" role="form">
            <input id="operation" name="operation" type="hidden" value="${operation!}"/>
            <input class="form-control" id="id" name="id" type="hidden" value="${apiFacadeMethod.id!}">
            <input class="form-control" id="docId" name="docId" type="hidden" value="${apiFacadeMethod.docId!}">
            <input class="form-control" id="requestIds" name="requestIds" type="hidden"
                   value="${apiFacadeMethod.requestIds!}">
            <input class="form-control" id="responseIds" name="responseIds" type="hidden"
                   value="${apiFacadeMethod.responseIds!}">
            <input class="form-control" id="objType" name="objType" type="hidden">
            <div class="form-group">
              <label class="col-sm-2 control-label">接口编码 ：</label>
              <div class="col-sm-6">
                <input class="form-control" id="apiFacadeCode" name="apiFacadeCode" readonly="readonly"
                       required="required"
                       type="text" value="${apiFacadeMethod.apiFacadeCode!}"/>
              </div>
              <#if (fromPage?? && fromPage!="tab")>
              <div class='col-sm-2'>
                <input class="primary-btn" id="selectFacadeDoc" onclick="ApiFacadeMethodMgr.selectFacadeDoc()"
                       type="button"
                       value='选择接口'/>
              </div>
            </#if>
            <div class="col-sm-1">
              <span class="required">*</span>
            </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">方法编码 ：</label>
          <div class="col-sm-8">
            <input class="form-control" id="methodCode" name="methodCode" required="required"
                   type="text"
                   value="${apiFacadeMethod.methodCode!}"/>
          </div>
          <div class="col-sm-1">
            <span class="required">*</span>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">方法名称 ：</label>
          <div class="col-sm-8">
            <input class="form-control" id="methodName" name="methodName" required="required"
                   type="text"
                   value="${apiFacadeMethod.methodName!}"/>
          </div>
          <div class="col-sm-1">
            <span class="required">*</span>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">方法请求对象：</label>
          <div class="col-sm-6">
            <input class="form-control" id="request" name="request" readonly="readonly" required="required"
                   type="text" value="${apiFacadeMethod.request!}"/>
          </div>
          <div class='col-sm-2'>
            <input class="primary-btn" id="selectRequest" onclick="ApiFacadeMethodMgr.selectObj('request')"
                   type="button"
                   value='选择请求对象'/>
          </div>
          <div class="col-sm-1">
            <span class="required">*</span>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">方法响应对象：</label>
          <div class="col-sm-6">
            <input class="form-control" id="response" name="response" readonly="readonly" required="required"
                   type="text" value="${apiFacadeMethod.response!}"/>
          </div>
          <div class='col-sm-2'>
            <input class="primary-btn" id="selectResponse" onclick="ApiFacadeMethodMgr.selectObj('response')"
                   type="button"
                   value='选择响应对象'/>
          </div>
          <div class="col-sm-1">
            <span class="required">*</span>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label text-right">接口方法内容分析：</label>
          <div class="col-sm-8">
									 <textarea class="col-sm-12" id="methodContentAnalysis" name="methodContentAnalysis" rows="70"
                             style="height:240px">${apiFacadeMethod.methodContentAnalysis!}</textarea>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label text-right">接口调用示例：</label>
          <div class="col-sm-8">
									<textarea class="col-sm-12" id="useMethod" name="useMethod" rows="70"
                            style="height:240px">${apiFacadeMethod.useMethod!}</textarea>
          </div>
        </div>
        </form>
      </div>
    </div>
  </div>
  <!-- end: PAGE -->
</div>
<!-- end: MAIN CONTAINER -->
</div>

<#include "/common/jslib.html">
<#include "/common/uploadlib.html">
<script type="text/javascript">
    KindEditor.ready(function (K) {
        useMethodTextArea = K.create('textarea[name="useMethod"]', {
            uploadJson: '/kindEditor/fileUpload',
            fileManagerJson: '/kindEditor/fileManager',
            allowFileManager: false,
            allowImageUpload: true,
            autoHeightMode: true,
            afterCreate: function () {
                this.loadPlugin('autoheight');
            },
            afterBlur: function () {
                this.sync();
            }  //Kindeditor下获取文本框信息
        });
    });
    KindEditor.ready(function (K) {
        methodContentAnalysisArea = K.create('textarea[name="methodContentAnalysis"]', {
            uploadJson: '/kindEditor/fileUpload',
            fileManagerJson: '/kindEditor/fileManager',
            allowFileManager: false,
            allowImageUpload: true,
            autoHeightMode: true,
            afterCreate: function () {
                this.loadPlugin('autoheight');
            },
            afterBlur: function () {
                this.sync();
            }  //Kindeditor下获取文本框信息
        });
    });
</script>
<!-- 弹窗下拉 -->
<script type="text/javascript">
    function returnIndex() {
        var fromPage = "${fromPage!}";
        if (fromPage == "tab") {
            window.location.href = "/apiFacadeMethod/query?docId=${apiFacadeMethod.docId}&fromPage=${fromPage!}";
        } else {
            window.location.href = "/apiFacadeMethod/query";
        }
    }

    $(function () {
        // 页面操作类型：add(添加)-edit(编辑)-view(查看)
        var operation = $("#operation").val();
        // 弹出窗体控制
        ApiFacadeMethodMgr = {
            // 初始化
            init: function () {
                // 查看的时候不显示保存按钮
                if (operation == "view") {
                    Jmts.setFormReadOnly();
                }
            },
            // init end

            // 提交数据
            submitForm: function () {
                $("#useMethod").val(useMethodTextArea.html());
                $("#methodContentAnalysis").val(methodContentAnalysisArea.html());
                Jmts.ajaxSubmit(document.getElementById("apiFacadeMethodForm"), function (result) {
                    if (result.success) {
                        if (operation == 'add') {
                            ApiFacadeMethodMgr.returnIndex();
                        } else {
                            Jmts.succTips(result.msg);
                            window.location.reload();
                        }
                    } else {
                        Jmts.warnTips(result.msg);
                    }
                });
                return false;
            },
            // submitForm end
            returnIndex: function () {
                window.location.href = "/apiFacadeMethod/query?docId=${docId!}&fromPage=${fromPage!}";
            },
            selectFacadeDoc: function () {//选择接口
                var url = "/apiFacadeDoc/query_select?selectType=single&returnMethod=ApiFacadeMethodMgr.initMethodInfo";
                Jmts.openDialog("selectFacadeDoc", url, "选择接口", 500, 800, 32);
            },
            initMethodInfo: function (data) {
                var docInfo = data.split(",");
                $("#docId").val(docInfo[0]);
                $("#apiFacadeCode").val(docInfo[1]);
            },
            selectObj: function (objType) {//选择request对象
                $("#objType").val(objType);
                var url = "/apiFacadeObj/query_select?selectType=multiple&returnMethod=ApiFacadeMethodMgr.initObjInfo&objType=" + objType;
                Jmts.openDialog("selectObj", url, "选择参数对象", 500, 800, 32);
            },
            initObjInfo: function (data) {

                var request = $("#request").val();
                var requestIds = $("#requestIds").val();
                var response = $("#response").val();
                var responseIds = $("#responseIds").val();

                var objType = $("#objType").val();
                var objInfo = data.split(",");
                var objCodes = "";
                var objIds = "";
                if (objInfo.length > 0) {
                    for (var i = 0; i < objInfo.length; i++) {
                        var objId = objInfo[i].split("#")[0];
                        var objCode = objInfo[i].split("#")[1];
                        if (objType == "request") {
                            if (requestIds.indexOf(objId) != -1) {
                                continue;
                            }
                        } else if (objType == "response") {
                            if (responseIds.indexOf(objId) != -1) {
                                continue;
                            }
                        }
                        if (i == 0) {
                            objIds += objId;
                            objCodes += objCode;
                        } else {
                            objIds += "," + objId;
                            objCodes += "," + objCode;
                        }
                    }
                }
                if (objType == "request") {
                    if (!Jmts.isEmpty(objCodes)) {
                        if (Jmts.isEmpty(request)) {
                            $("#request").val(objCodes);
                        } else {
                            $("#request").val(request + "," + objCodes);
                        }
                    }
                    if (!Jmts.isEmpty(objIds)) {
                        if (Jmts.isEmpty(requestIds)) {
                            $("#requestIds").val(objIds);
                        } else {
                            $("#requestIds").val(requestIds + "," + objIds);
                        }
                    }
                } else if (objType == "response") {
                    if (!Jmts.isEmpty(objCodes)) {
                        if (Jmts.isEmpty(response)) {
                            $("#response").val(objCodes);
                        } else {
                            $("#response").val(response + "," + objCodes);
                        }
                    }
                    if (!Jmts.isEmpty(objIds)) {
                        if (Jmts.isEmpty(responseIds)) {
                            $("#responseIds").val(objIds);
                        } else {
                            $("#responseIds").val(responseIds + "," + objIds);
                        }
                    }
                }
            }
        };
        // 执行初始化
        ApiFacadeMethodMgr.init();
        // 前台验证表单
        $("#apiFacadeMethodForm").validate();
    });
</script>
</body>
</html>
